#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e5+1000;
typedef long long LL;
struct Ans{
    LL x,y;
}ANS[maxn];
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL t;cin>>t;
  while(t--){
    LL sum=0;
    LL n;cin>>n;
    for(LL i=0;i<=n+100;i++) ANS[i].x=0,ANS[i].y=0;
    LL temp=n;
    if(n==3){
        cout<<2<<endl;
        cout<<"3"<<" "<<"2"<<endl;
        cout<<"3"<<" "<<"2"<<endl;
        continue;
    }
    for(LL i=n-1;i>=3;i--){
        if(i*i<=temp){
            ANS[++sum].x=n;ANS[sum].y=i;
            temp=ceil(1.0*temp/i);
        }
        ANS[++sum].x=i;ANS[sum].y=n;
    }
    while(temp>1){
        ANS[++sum].x=n;ANS[sum].y=2;
        temp=ceil(1.0*temp/2);
    }
    cout<<sum<<endl;
    for(LL i=1;i<=sum;i++){
        cout<<ANS[i].x<<" "<<ANS[i].y<<endl;
    }
  }
return 0;
}
